package com.ewivt.excel.utils;

import java.io.*;

public class ArrayUtils {

    @SuppressWarnings("unchecked")
    public static <T extends Serializable> T clone(T obj) {
        T clonedObj = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(obj);
            oos.close();
            ByteArrayInputStream bais = new  ByteArrayInputStream(baos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bais);
            clonedObj = (T) ois.readObject();
            ois.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return clonedObj;
    }

    public static double[][] getTwoDimensionalArrayWithDirInitData(int x,int y ,double init){
        double[][] array = new double[x][y];
        for (int i=0;i<x;i++){
            for (int j =0 ;j< y;j++){
                array[i][j] = init;
            }
        }
        return array;
    }
    public static double[] getOneDimensionalArrayWithDirInitData(int x ,double init){
        double[] array = new double[x];
        for (int i = 0;i <x;i++){
            array[i] = init;
        }
        return array;
    }
}
